using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace sharpserver
{
    class HideButton : Button
    {
        private Brush myBrush = Brushes.Black;
        private ToolTip tip = new ToolTip();

        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            int centre = (int)Math.Floor((double)this.Width / 2);

            Graphics g = pevent.Graphics;
            Rectangle r = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
            g.FillRectangle(Brushes.LightGray, new Rectangle(0, 0, this.Width, this.Height));
            g.DrawEllipse(new Pen(myBrush, 2), 2, 2, this.Width - 5, this.Height - 5);
            g.DrawLine(new Pen(myBrush, 2), new Point(centre, 6), new Point(centre, this.Height - 9));
            g.FillPolygon(myBrush, new Point[] {
                new Point(centre, this.Height - 5), 
                new Point(centre - 7, (int)Math.Ceiling((double)this.Height / 2) - 2), 
                new Point(centre, (int)Math.Ceiling((double)this.Height / 2) + 1),
                new Point(centre, (int)Math.Ceiling((double)this.Height / 2) + 1),
                new Point(centre + 7, (int)Math.Ceiling((double)this.Height / 2) - 2), 
                new Point(centre, this.Height - 5)
            });
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            this.myBrush = Brushes.Red;
            this.Invalidate();
            this.tip.Show("Hide this window", this);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.myBrush = Brushes.Black;
            this.Invalidate();
            this.tip.Hide(this);
        }
    }
}
